﻿using System;

namespace PizzaMario.Domain.Abstract
{
    // The pattern for disposing an object, referred to as a dispose pattern, imposes order on the lifetime of an object. 
    // The dispose pattern is used only for objects that access unmanaged resources. 
    // This is because the garbage collector is very efficient at reclaiming unused managed objects.
    // http://msdn.microsoft.com/en-us/library/fs2xkftw.aspx
    public class Disposable : IDisposable
    {
        private bool _isDisposed;

        #region IDisposable Members

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        #endregion

        ~Disposable()
        {
            Dispose(false);
        }

        private void Dispose(bool disposing)
        {
            if (!_isDisposed && disposing)
                DisposeCore();

            _isDisposed = true;
        }

        protected virtual void DisposeCore()
        {
        }
    }
}
